package com.iknow.activity;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.iknow.IKnow;
import com.iknow.file.CacheSystem;
import com.iknow.task.GenericTask;
import com.iknow.task.TaskAdapter;
import com.iknow.task.TaskListener;
import com.iknow.task.TaskParams;
import com.iknow.task.TaskResult;
import com.iknow.util.MsgDialog;
import com.iknow.util.MsgDialog.ProgressHandler;
import com.iknow.util.MsgDialog.ProgressRunnable;
import com.iknow.util.SystemUtil;
import java.io.File;

public class SystemReferencesActivity extends Activity
{
  public LinearLayout aboutIknow;
  public Button back;
  public TextView cacheSize;
  public LinearLayout cacheView;
  public LinearLayout feedIknow;
  public String mString;
  protected TaskListener mTaskListener;
  public TextView toolBar = null;

  public SystemReferencesActivity()
  {
    this.back = null;
    this.mString = "0.0M";
    this.cacheView = null;
    this.cacheSize = null;
    this.aboutIknow = null;
    this.feedIknow = null;
    this.mTaskListener = new TaskAdapter(this)
    {
      protected ProgressDialog pd = null;

      public String getName()
      {
        return null;
      }

      public void onCancelled()
      {
        this.pd.dismiss();
        super.onCancelled(paramGenericTask);
      }

      public void onPostExecute(, TaskResult paramTaskResult)
      {
        this.this$0.cacheSize.setText("清除缓存的临时文件,当前缓存大小" + this.this$0.mString);
        this.pd.dismiss();
        super.onPostExecute(paramGenericTask, paramTaskResult);
      }

      public void onPreExecute()
      {
        this.pd = ProgressDialog.show(this.this$0, "提示", "正在读取文件数据...");
        this.this$0.initView();
        super.onPreExecute(paramGenericTask);
      }

      public void onProgressUpdate(, Object paramObject)
      {
        super.onProgressUpdate(paramGenericTask, paramObject);
      }
    };
  }

  private int getCacheFileSize()
  {
    int k;
    File[] arrayOfFile = new File(SystemUtil.getSDPath() + File.separator + "iknow" + File.separator + "cache" + File.separator).listFiles();
    if (arrayOfFile == null)
    {
      k = 0;
      return k;
    }
    int i = 0;
    int j = 0;
    while (true)
    {
      while (j >= arrayOfFile.length)
        k = i;
      i = (int)(i + arrayOfFile[j].length());
      ++j;
    }
  }

  public File getCacheFile()
  {
    return new File(SystemUtil.getSDPath() + File.separator + "iknow" + File.separator + "cache" + File.separator);
  }

  public void getLocalData()
  {
    LocalDataTask localLocalDataTask = new LocalDataTask(this);
    localLocalDataTask.setListener(this.mTaskListener);
    localLocalDataTask.execute(new TaskParams[0]);
  }

  public void initView()
  {
    this.back = ((Button)findViewById(2131296342));
    this.cacheView = ((LinearLayout)findViewById(2131296538));
    this.cacheSize = ((TextView)findViewById(2131296539));
    this.aboutIknow = ((LinearLayout)findViewById(2131296541));
  }

  protected void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    requestWindowFeature(1);
    setContentView(2130903130);
    this.toolBar = ((TextView)findViewById(2131296343));
    this.toolBar.setText("设置");
    findViewById(2131296344).setVisibility(8);
    getLocalData();
    this.back.setOnClickListener(new View.OnClickListener(this)
    {
      public void onClick()
      {
        this.this$0.finish();
      }
    });
    this.cacheView.setOnClickListener(new View.OnClickListener(this)
    {
      public void onClick()
      {
        MsgDialog.showB2Dilog(this.this$0, 2131361884, new DialogInterface.OnClickListener(this)
        {
          public void onClick(, int paramInt)
          {
            switch (paramInt)
            {
            default:
            case -1:
            }
            while (true)
            {
              return;
              MsgDialog.showProgressDialog(SystemReferencesActivity.3.access$0(this.this$1), new MsgDialog.ProgressRunnable(this)
              {
                public boolean runnable()
                {
                  if (SystemReferencesActivity.3.access$0(SystemReferencesActivity.3.1.access$0(this.this$2)).getCacheFile().exists())
                    SystemReferencesActivity.3.access$0(SystemReferencesActivity.3.1.access$0(this.this$2)).getCacheFile().delete();
                  IKnow.mCacheSystem.clearCache();
                  paramHandler.obtainMessage().sendToTarget();
                  return true;
                }
              }
              , new MsgDialog.ProgressHandler(this)
              {
                public void handleMessage(, ProgressDialog paramProgressDialog)
                {
                  SystemReferencesActivity.3.access$0(SystemReferencesActivity.3.1.access$0(this.this$2)).cacheSize.setText("清除缓存的临时文件,当前缓存大小0.0M");
                  Toast.makeText(SystemReferencesActivity.3.access$0(SystemReferencesActivity.3.1.access$0(this.this$2)), "已清除缓存", 0).show();
                }
              });
            }
          }
        });
      }
    });
    this.aboutIknow.setOnClickListener(new View.OnClickListener(this)
    {
      public void onClick()
      {
        Intent localIntent = new Intent(this.this$0, AboutActivity.class);
        this.this$0.startActivity(localIntent);
      }
    });
  }

  public float unitConversion(long paramLong)
  {
    return (float)(Math.round(1000.0F * (float)(paramLong / 1024L) / 1024.0F) / 1000.0D);
  }

  public class LocalDataTask extends GenericTask
  {
    protected TaskResult _doInBackground()
    {
      int i = SystemReferencesActivity.access$0(this.this$0);
      if (i > 0)
      {
        float f = this.this$0.unitConversion(i);
        this.this$0.mString = String.valueOf(f) + "M";
      }
      return TaskResult.OK;
    }
  }
}